package com.example.service.webhook.business.taobao.repository;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.example.service.webhook.business.taobao.entity.SubOrderEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
/**
 * 这里用的是jdbctemplate，DAO层可以根据自己的业务来选择
 * ClassName: TaobaoSuborderRepository
 * date: 2016年7月19日 下午6:29:23   
 * @author yuandong  
 * @version   
 * @since JDK 1.6
 */
@Repository
public class TaobaoSuborderRepository extends BaseDAO<SubOrderEntity>{
	
	@Resource(name="templateTaobao")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
    
    public void saveSubOrder(SubOrderEntity entity)throws Exception  {
    	entity.setCreateTime(DateUtil.getCurrentDate());
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.add(entity);
    }
    
    public void deleteSubOrder(String userId,String mappingId,String tradeId){
 	   String tableName = "t_taobao_suborder";
 	        StringBuilder sql = new StringBuilder("DELETE FROM ").append(tableName).append(" WHERE ").
 	                append("userId='").append(userId).append("'").
 	                append("and mappingId='").append(mappingId).append("'").
	                append("and tradeId='").append(tradeId).append("'");

 	         this.getJdbcTemplate().update(sql.toString());
    }

    
    
    
}
